<%@ page language="java" contentType="text/html; charset=UTF8"
    pageEncoding="UTF8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF8">
<title>BookStore - 登录</title>
<link rel="icon" href="res/img/icon.png" type="image/x-icon" />
<script src="./res/js/jquery.js"></script>
</head>
<body>
	<div>	
  	<h2>登录</h2>
 	账号:<input id="login_userID" type="text" value=""><br>
	密码:<input id="login_password" type="text" value=""><br>
	<br>
  	<input  id='login_btn' type="button" value="登录">
  	<input  id='btn2' type="button" value="查询">
  	</div>
  	<!-- input  id='login_btn2' type="button" value="发送请求" -->
  	
  	<div>
 	<h2>注册</h2>
 	账号:<input id="register_userID" type="text" value=""> *<br>
	密码:<input id="register_password" type="text" value=""> *<br>
	确认密码:<input id="register_password2" type="text" value=""> *<br>
	用户名:<input id="register_userName" type="text" value=""><br>
	手机号:<input id="register_phoneNumber" type="text" value=""><br>
	邮箱:<input id="register_email" type="text" value=""><br>
	地址:<input id="register_address" type="text" value=""><br>
	<br>
	
  	<input  id='register_btn' type="button" value="注册">
  	<input  id='btn3' type="button" value="重置">
  	</div>
	<script type="text/javascript">
	
	$(document).ready(function(){
		$('#login_btn').click(function (){
			var formData = {
					userID:'',
					password:'',
			}
			formData.userID = $('#login_userID').val()
			formData.password = $('#login_password').val()
			if(formData.userID==''||formData.password==''){
				alert('账号或密码不能为空');	
			}else{
				$.post("Login",formData,function(data){
					console.log("status:"+data.status+"\nmessage:"+data.message+"\ndata:"+JSON.stringify(data.data));
					switch(data.status){
					case 1:
						$(location).attr('href', 'index.jsp');
						break;
					case -1:
						alert(data.message);
						break;
					case -2:
						alert(data.message);
						break;
					default:
						alert('Server Error');
					}
				  });
			}
		});
		
		$('#btn2').click(function (){
			var userData = {
					userID:'',
			}
			userData.userID = $('#login_userID').val()
			$.post(
					"Servlet2",
					userData,
					function(data,status)
					{
						alert("status:"+data.status+"\nmessage:"+data.message+"\ndata:"+JSON.stringify(data.data));
					}
			);
		});	
		
		$('#register_btn').click(function (){
			var formData = {
					userID:'',
					password:'',
					userName:'',
					phoneNumber:'',
					email:'',
					address:'',
			}
			formData.userID = $('#register_userID').val()
			formData.password = $('#register_password').val()
			formData.userName = $('#register_userName').val()
			formData.phoneNumber = $('#register_phoneNumber').val()
			formData.email = $('#register_email').val()
			formData.address = $('#register_address').val()
			var password2 = $('#register_password2').val()
			
			if(formData.userID==''||formData.password==''){
				alert('账号或密码不能为空');	
			}else{
				if(password2==''){
					alert('确认密码不能为空');	
				}else{
					if(formData.password != password2){
						alert('密码与确认密码不一致');
					}else{
						alert('注册成功');
						console.log(formData);
						$.post(
								"Register",
								formData,
								function(data,status)
								{
									
									
									alert("status:"+data.status+"\nmessage:"+data.message+"\ndata:"+JSON.stringify(data.data));
								}
						);
					}
				}
				
			}
		});	
		
	});
	
	</script>
	
</body>
</html>